package com.woniu.inlet.web.controller;

import com.woniu.exception.SignException;
import com.woniu.outlet.mysql.po.Sign;
import com.woniu.service.SignService;
import com.woniu.utils.ResultResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.Service;

@RestController
@Api("签到模块功能测试")
public class SignController {

    @Autowired
    private SignService signService;

    //查询用户是否已经签到
    @GetMapping("/sign/check")
    @ApiOperation("查询是否已经签到了")
    public ResultResponseUtil hasSign(Integer userId) {
        try {
            Sign sign = signService.hasSign(userId);
            return new ResultResponseUtil(sign);
        } catch (Exception e) {
            if (e instanceof SignException) {
                e.printStackTrace();
            }
            return new ResultResponseUtil(500,"系统维护中");
        }
    }

    @ApiOperation("执行签到")
    @GetMapping("/sign/do")
    public Object doSign(Integer userId) {
        try {
            signService.doSign(userId);
            return new ResultResponseUtil<>("今日签到成功！！！");
        } catch (Exception e) {
            if (e instanceof SignException)
                return new ResultResponseUtil(e.getMessage());
            else
                return new ResultResponseUtil<>(500,"签到系统维护中，请稍后再试");
        }
    }

}
